package org.idea.qiyu.framework.sqlsession.factory.mapping.utils;

import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.core.env.Environment;

import java.util.Collections;
import java.util.Map;

/**
 * @Author linhao
 * @Date created in 6:25 下午 2021/5/27
 */
public class EnvironmentUtils {

    private EnvironmentUtils() {
        throw new IllegalStateException("Can't instantiate a utility class");
    }

    public static Map<String, String> getSubProperties(Environment environment,
                                                       String keyPrefix) {
        return Binder.get(environment)
                .bind(keyPrefix, Bindable.mapOf(String.class, String.class))
                .orElseGet(Collections::emptyMap);
    }

}
